<template>
    <div class="card">
        <!-- {{this.cardData}} -->
        <div class="block">
            <div v-if="this.cardData == ''" class="noEquipment"> 
                该项绑定设备未开启
            </div>
            <el-carousel trigger="click" class="card_hight" :autoplay="false" :initial-index="cardData.index" >
            <el-carousel-item v-for="item in cardData.unit" :key="item.index">
                <!-- 设备标题 -->
                <router-link to="/overview">
                    <h4 class="normal" @click="router('airclean',item)" :title="item.name">
                    <!-- <svg class="icon card_icon" aria-hidden="true">
                        <use xlink:href="#icon-xinfeng-copy"></use>
                    </svg> -->
                    <img class="title_icon" src="../../assets/title.png" alt />
                    {{item.typename}}:&nbsp;{{item.name}}
                 </h4>
                </router-link>
                <!-- 卡片内容 -->
                <div class="card_padding">
                    <div ref="airclean_aqi" class="top">   
                        <div class="airclean_pm">
                            <p class="airclean_pm_name">{{item.unit[3].name}}:</p>
                            <p class="airclean_pm_val">
                                <span style="color:#32b16c" v-if="item.unit[3].value <= 35">{{item.unit[3].value.toFixed(0)}}</span>
                                <span style="color:#facd86" v-if="item.unit[3].value > 35 && item.unit[3].value <= 75">{{item.unit[3].value.toFixed(0)}}</span>
                                <span style="color:#c8651d" v-if="item.unit[3].value > 75 && item.unit[3].value <= 115">{{item.unit[3].value.toFixed(0)}}</span>
                                <span style="color:#ff5c5c" v-if="item.unit[3].value > 115 && item.unit[3].value <= 150">{{item.unit[3].value.toFixed(0)}}</span>
                                <span style="color:#9f58c2" v-if="item.unit[3].value > 150 && item.unit[3].value <= 250">{{item.unit[3].value.toFixed(0)}}</span>
                                <span style="color:#ab0000" v-if="item.unit[3].value > 250">{{item.unit[3].value.toFixed(0)}}</span>
                            </p>
                            <p class="airclean_pm_flag">{{item.unit[3].flag}}</p>
                        </div>
                        <div class="airclean_pm2 ">
                            <span style="margin-right:5px">AQI</span>
                            <span v-if="item.unit[3].value <= 35">优</span>
                            <span v-if="item.unit[3].value > 35 && item.unit[3].value <= 75">良</span>
                            <span v-if="item.unit[3].value > 75 && item.unit[3].value <= 115">轻度污染</span>
                            <span v-if="item.unit[3].value > 115 && item.unit[3].value <= 150">中度污染</span>
                            <span v-if="item.unit[3].value > 150 && item.unit[3].value <= 250">重度污染</span>
                            <span v-if="item.unit[3].value > 250">严重污染</span>
                        </div>
                    </div>
                    <div class="airclean_bottom" style="margin-top:8px">
                        <div v-if="item.unit[5].ready == 1" class="airfilter_border">
                            <p class="p3" style="color: #32b16c">{{item.unit[5].value.toFixed(1)}} <span>{{item.unit[5].flag}}</span></p>
                            <p class="p4">{{item.unit[5].name}}</p>
                        </div>
                        <div v-if="item.unit[1].ready == 1" class="airfilter_border">
                            <p class="p3" style="color: #32b16c">{{item.unit[1].value.toFixed(0)}} <span>{{item.unit[1].flag}}</span></p>
                            <p class="p4">{{item.unit[1].name}}</p>
                        </div>
                        <div v-if="item.unit[4].ready == 1">
                            <p class="p3" style="color: #32b16c">{{item.unit[4].value.toFixed(0)}} <span>{{item.unit[4].flag}}</span></p>
                            <p class="p4">{{item.unit[4].name}}</p>
                        </div>
                    </div>
                    <div class="airclean_bottom airfilter_center">
                        <div v-if="item.unit[6].ready == 1" class="airfilter_border">
                            <p class="p3" style="color: #38bdea">{{item.unit[6].value.toFixed(1)}} <span>{{item.unit[6].flag}}</span></p>
                            <p class="p4">{{item.unit[6].name}}</p>
                        </div>
                        <div v-if="item.unit[2].ready == 1" class="airfilter_border">
                            <p class="p3" style="color: #38bdea">{{item.unit[2].value.toFixed(0)}} <span>{{item.unit[2].flag}}</span></p>
                            <p class="p4">{{item.unit[2].name}}</p>
                        </div>
                        <div v-if="item.unit[0].ready == 1">
                            <p class="p3" style="color: #38bdea">{{item.unit[0].value.toFixed(0)}} <span>{{item.unit[0].flag}}</span></p>
                            <p class="p4">{{item.unit[0].name}}</p>
                        </div>
                    </div>
                    <div class="airclean_bottom">
                        <div v-if="item.unit[9].ready == 1">
                            <p class="p5"> <span :class="item.unit[9].value == 1 ? 'p5_green':'p5_gray'">开机</span><span style="margin:0 5px">|</span><span :class="item.unit[9].value == 0 ? 'p5_green':'p5_gray'">关机</span> </p>
                        </div>
                        <div v-if="item.unit[8].ready == 1">
                            <p class="p5"> <span :class="item.unit[8].value == 1 ? 'p5_green':'p5_gray'">自动</span><span style="margin:0 5px">|</span><span :class="item.unit[8].value == 0 ? 'p5_green':'p5_gray'">手动</span> </p>
                        </div>
                        <div v-if="item.unit[7].ready == 1">
                            <p class="p5"> <span :class="item.unit[7].value == 1 ? 'p5_green':'p5_gray'">低速</span><span style="margin:0 5px">|</span><span :class="item.unit[7].value == 0 ? 'p5_green':'p5_gray'">高速</span> </p>
                        </div>
                    </div>
                </div>
                 
            </el-carousel-item>
            </el-carousel>
        </div>
        
    </div>
</template>

<script>
export default {
    props: ['nowIndex', 'cardData', 'nowId'],
    data () {
        return{
            timergetCardData : '', //获取缓存中的数据 定时器
            time: '' //定时器
        }
    },
    created() {
        this.getCardData();
        // 从缓存获取数据定时器
        this.timergetCardData = setInterval(() => {
            setTimeout(this.getCardData(), 0);
        }, this.$store.state.requestTime);
    },
    mounted(){
        if(this.cardData.unit[this.cardData.index]!== undefined){
            this.getAqi(this.cardData.unit[3].value)
        }else{}
        
    },
    methods: {
        // 跳转
        router(val,item){
            var arr = {
                addr:item.addr,
                name:item.name,
                type:item.type,
                uid:item.uid
            }
            localStorage.setItem("当前设备编号", JSON.stringify(arr))
            localStorage.setItem("menuRouter", val)
        },
        getAqi(val){
            // console.log(this.$refs.airclean_aqi)
            if(val <= 35){
                this.$refs.airclean_aqi[this.cardData.index].setAttribute("class", "top airclean_pm_color1");
            }else if(val > 35 && val <= 75){
                this.$refs.airclean_aqi[this.cardData.index].setAttribute("class", "top airclean_pm_color2");
            }else if(val > 75 && val <= 115){
                this.$refs.airclean_aqi[this.cardData.index].setAttribute("class", "top airclean_pm_color3");
            }else if(val > 115 && val <= 150){
                this.$refs.airclean_aqi[this.cardData.index].setAttribute("class", "top airclean_pm_color4");
            }else if(val > 150 && val <= 250){
                this.$refs.airclean_aqi[this.cardData.index].setAttribute("class", "top airclean_pm_color5");
            }else if(val > 250){
                this.$refs.airclean_aqi[this.cardData.index].setAttribute("class", "top airclean_pm_color6");
            }
        },
        getCardData () {
            if(this.$refs.airclean_aqi == undefined){
            }else{
                this.getAqi(this.cardData.unit[this.cardData.index].unit[3].value)
            }           
        },
    },
     // 清除定时器
    beforeDestroy() {
        clearInterval(this.timergetCardData);
        this.timergetCardData = null;
    },
}
</script>

<style scoped>

/deep/ .el-carousel__container .el-carousel__arrow {
    height: 150px !important;
    width: 110px !important;
    border-radius: 0;
    background: none;
}
/deep/ .el-icon-arrow-left {
    margin-left: -110px !important;
}
/deep/ .el-icon-arrow-right{
    margin-right: -110px !important;
}
/deep/ .el-carousel__indicators{
    display: none;
}
.card_padding .item{
    width: 100%;
    height: 25px;
    float: left;
    /* text-align: center; */
    font-size: 18px;
    margin: 12px 0;
}
.normal .card_icon{
    font-size: 20px;
}
.li{
    display: flex;
    margin-bottom: 3px;
}
/deep/ .progress_title {
    /* display: inline-block; */
    width: 130px;
    line-height: 24px;
    float: left;
    /* flex: 1; */
    font-size: 16px;

}
/deep/ .el-progress{
    padding: 4px 0;
    padding-right: 15px;
    width: 250px;
    /* flex: 1; */
}
.progress_value{
    float: right;
    /* flex: 1; */
    text-indent: 20px;
    width: 130px;
    line-height: 26px;
    height: 30px;

}
/deep/ .el-progress-bar__outer{
    background: none;
    border: .5px solid rgba(89, 129, 165, 0.8);
}
/deep/ .li:nth-child(1) .el-progress-bar__inner{
    background: #328be8;
}
/deep/ .li:nth-child(2) .el-progress-bar__inner{
    background: #60b1e2;
}
/deep/ .li:nth-child(3) .el-progress-bar__inner{
    background: #328be8;
}
/deep/ .li:nth-child(4) .el-progress-bar__inner{
    background: #60b1e2;
}
/deep/ .card_padding {
    padding: 0px 20px 0px 30px !important;
}

.top{
    display: flex;
    width: 395px;
    margin: 0 auto;
    margin-top: 20px;
    justify-content: space-between;
    border-radius: 20px;
}
.airclean_pm{
    display: flex;
    /* justify-content: space-evenly; */
    align-items: center;
    /* flex-direction: column; */
}
.airclean_pm2{
    /* width: 130px; */
    padding-right: 30px;
    text-align: center;
    line-height: 37px;
    font-size: 18px;
    position: relative;
    top: 2px;
}
.airclean_pm_color1{
    background: linear-gradient(to right , rgba(255, 0, 0, 0), #2178679e 60%);
}
.airclean_pm_color2{
    background: linear-gradient(to right , rgba(255, 0, 0, 0), #a684369e 60%);
}
.airclean_pm_color3{
    background: linear-gradient(to right , rgba(255, 0, 0, 0), #c8651d9e 60%);
}
.airclean_pm_color4{
    background: linear-gradient(to right , rgba(255, 0, 0, 0), #ff5c5c9e 60%);
}
.airclean_pm_color5{
    background: linear-gradient(to right , rgba(255, 0, 0, 0), #5e2c769e 60%);
}
.airclean_pm_color6{
    background: linear-gradient(to right , rgba(255, 0, 0, 0), #530c0c 60%);
}
.airclean_pm_name{
    font-size:  18px;
    width: 60px;
    overflow: hidden;
}
.airclean_pm_val{
    font-size:  28px;
    margin-left: 10px;
}
.airclean_pm_flag{
    color: #acacac;
    font-size: 16px;
    margin-left: 10px;
}
.airclean_pm_zt{
    width: 50px;
    height: 50px;
    background-color: #409685;
    border-radius: 100%;
    display: flex;
    justify-content: space-evenly;
    align-items: center;
    flex-direction: column;
}
.airclean_bottom{
    display: flex;
    text-align: center;
    margin-top: 14px;
}
.airfilter_center{
    margin-top: 0px;
}
.airfilter_center>div{
    padding-top: 6px;
}
.airclean_bottom>div{
    flex: 1;
}
.airfilter_border{
    border-right: 1px dashed #d8d8d894;
}
.p3{
    width: 135px;
    overflow: hidden;
    margin: 0 auto;
    font-size: 24px;
    font-weight: 500;
    text-align: center;
    line-height: 35px;
    text-indent: 0px;
    white-space: nowrap;
}
.p3 span{
    color: #bbbbbb;
    font-size: 15px;
}
.p4{
    overflow: hidden;
    width: 102px;
    margin: 0 auto;
    white-space: nowrap;
        margin-top: -4px;
    font-size: 14px;
}
.p5{
    width: 105px;
    margin: 0 auto;
    font-size: 17px;
    font-weight: 500;
    text-align: center;
    line-height: 40px;
    text-indent: 0px;
    /* color: #C45911; */
    color: #facd86;
    font-weight: lighter;
}
.p5_green{
    color: #38bdea;
    /* color: #2E74B5; */
}
.p5_gray{
    color: #bbbbbb;
}
</style>